package com.dai.spec.gxk.service.impl;

import com.dai.spec.common.constant.RoleConstants;
import com.dai.spec.common.core.domain.entity.SysUser;
import com.dai.spec.common.exception.base.BaseException;
import com.dai.spec.common.utils.SecurityUtils;
import com.dai.spec.gxk.mapper.StudentScoreMapper;
import com.dai.spec.gxk.request.StudentScorePageRequest;
import com.dai.spec.gxk.service.StudentScoreService;
import com.dai.spec.gxk.vo.StudentScoreVO;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentScoreServiceImpl implements StudentScoreService {

private StudentScoreMapper studentScoreMapper;

    public StudentScoreServiceImpl(StudentScoreMapper studentScoreMapper) {
        this.studentScoreMapper = studentScoreMapper;
    }

    /**
     * 分页查询所有学生成绩
     * @param pageRequest
     * @return
     */
    @Override
    public List<StudentScoreVO> queryScoreList(StudentScorePageRequest pageRequest) {
        PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getPageSize());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long roleId = user.getRoles().get(0).getRoleId();

            if (!RoleConstants.ACADEMIC_ADMIN.equals(roleId)) {
                throw new BaseException("当前登录用户不为教务管理员，无权限！");
            }
                List<StudentScoreVO> studentScoreVOS = studentScoreMapper.queryScoreList(pageRequest);

        return studentScoreVOS;
    }
}
